#!groovy
node { // <1>
// test
    stage('Build') { // <2>
        sh 'projectName=${PWD##*/} &&\
        cd ../${projectName}@script/coredataTest && \
        xcodebuild build-for-testing -workspace EarthQuake.xcworkspace -scheme EarthQuake -destination generic/platform=ios'
    }
    stage('Test') {
        sh 'projectName=${PWD##*/} &&\
        cd ../${projectName}@script/coredataTest && \
        xcodebuild test -workspace EarthQuake.xcworkspace -scheme EarthQuake -destination \'platform=IOS,id=a3076d5904e84acdc6896f30052c9af31bb01283\''
    }
    stage('Deploy') {
        sh 'projectName=${PWD##*/} &&\
        nowdate=`date +%m%d%H%M` &&\
        cd ../${projectName}@script/coredataTest && \
        mkdir ../../${projectName}/${nowdate} &&\
        xcodebuild -workspace EarthQuake.xcworkspace -scheme EarthQuake -archivePath ../../${projectName}/${nowdate}/${projectName} archive && \
        xcodebuild -exportArchive -archivePath ../../${projectName}/${nowdate}/${projectName}.xcarchive   -exportPath ../../${projectName}/${nowdate} -exportOptionsPlist ../JenkinsFile/export.plist'
    }
}